
public class Matrix {
	
	public  void setZero(int[][] matrix){
		
		if(matrix == null){
			return;
		}
		
		boolean[] row = new boolean[matrix.length];
		boolean[] column = new boolean[matrix[0].length];
		
		for(int i = 0; i < matrix.length; i++){
			for(int j = 0; j < matrix[0].length; j++){
				if(matrix[i][j] == 0){
					row[i] = true;
					column[j] = true;
				}
			}
		}
		
		for(int i = 0; i < matrix.length; i++){
			for(int j = 0; j < matrix[0].length; j++){
				if(row[i] || column[j]){
					matrix[i][j] = 0;
				}
			}
		}
	}
	
	public  void printMatrix(int[][] testArray){
		if(testArray == null){
			return;
		}
		for(int i = 0; i < testArray.length; i++){
			for(int j = 0; j < testArray[0].length; j++){
				if(j != testArray[0].length - 1){
					System.out.print(testArray[i][j]);
				}
				else{
					System.out.println(testArray[i][j]);
				}
				}
			}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Matrix test = new Matrix();
		int[][] testArray = {{1,3,4,1,5}, {0,2,3,4,0}, {1,1,1,1,1}};
		test.printMatrix(testArray);
		test.setZero(testArray);
		System.out.println();
		test.printMatrix(testArray);
		
		
		}
		
		
	

}
